package com.ferryc.controller;

import com.ferryc.entity.Order;
import com.ferryc.entity.Products;
import com.ferryc.model.OrderReq;
import com.ferryc.model.Product;
import com.ferryc.model.Result;
import com.ferryc.service.IOrderService;
import com.ferryc.service.impl.OrderServiceImpl;
import com.ferryc.tcc.IOrderTccService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * Created by Ferry Chen on 2019/11/1.
 */
@Api(tags = {"订单接口"})
@Slf4j
@RestController
@RequestMapping(value = "/order",produces = MediaType.APPLICATION_JSON_VALUE )
public class OrderController {
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private IOrderService orderService;
    @Autowired
    private IOrderTccService orderTccService;

    /**
     * 新增订单信息
     * 新增订单明细信息
     *
     * @return
     */

    @ApiOperation(value = "新增订单", notes = "新增订单")
    @PostMapping("/add")
    public Result add(@RequestBody OrderReq orderReq) {
        //orderService.saveOrder(orderReq.getUserId(), orderReq.getProductList());
        String orderId = UUID.randomUUID().toString();
        orderTccService.saveOrder(orderId, orderReq.getUserId(), orderReq.getProductList());
        return Result.success("ok");
    }


}
